/*
 * Project Name:hbm-be.
 * File Name:CsSmNoticeDao.java
 * Package Name:com.hginfo.cs.be.dao.cs
 * Date:2018年04月24日 下午3:58:49
 * Copyright (c) 2016, hongguaninfo.com All Rights Reserved.
 *
 */
package cn.uce.sms.srv.service;

import cn.uce.base.page.Page;
import cn.uce.base.page.Pagination;
import cn.uce.sms.entity.CsSmNotice;
import cn.uce.sms.entity.CsSmNoticeViewRecord;
import cn.uce.sms.srv.dao.impl.ICsSmNoticeDao;
import cn.uce.sms.srv.dao.impl.ICsSmNoticeViewRecordDao;
import cn.uce.sms.vo.CsSmNoticeVo;
import cn.uce.web.common.base.CurrentUser;
import cn.uce.web.common.util.WebUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 公告表: cs_sm_notice. <br />
 * dao 层 <br />
 * Date: 2018年04月24日 下午3:58:49 <br />
 *
 * @author you
 * @since V1.0.0
 */
@Service("csSmNoticeService")
public class CsSmNoticeService {

	@Autowired
	private ICsSmNoticeDao csSmNoticeDao;

	@Autowired
	private ICsSmNoticeViewRecordDao csSmNoticeViewRecordDao;

	public List<CsSmNoticeVo> getNewCsSmNotice(String createEmp) {
		 return csSmNoticeDao.getNewCsSmNotice(createEmp);
	}

	public Pagination<CsSmNoticeVo> getList(CsSmNoticeVo csSmNoticeVo, Page page){
		return csSmNoticeDao.getList(csSmNoticeVo,page);
	}

	public CsSmNotice findById(Long id){
		return csSmNoticeDao.findById(id);
	}

	public int deleteById(Long id){
		return csSmNoticeDao.deleteById(id);
	}

	public int updateById(CsSmNotice csSmNotice){
		return csSmNoticeDao.updateById(csSmNotice);
	}

	/**
	 * 查看公告详情
	 * @param id
	 * @return
	 */
	public CsSmNotice seeCsSmNotice(Long id){
		CsSmNotice csSmNotice = new CsSmNotice();
		csSmNotice.setId(id);
		csSmNoticeDao.updCsSmNoticeViewNum(csSmNotice);
		//获取当前登录用户
		CurrentUser current = WebUtil.getCurrentUser();
		CsSmNoticeViewRecord csSmNoticeViewRecord = new CsSmNoticeViewRecord();
		csSmNoticeViewRecord.setCreateEmp(current.getEmpCode());
		csSmNoticeViewRecord.setCreateTime(new Date());
		csSmNoticeViewRecord.setCreateOrg(current.getOrgId());
		csSmNoticeViewRecord.setNoticeId(id);
		csSmNoticeViewRecordDao.addCsSmNoticeViewRecord(csSmNoticeViewRecord);
	  // csSmNoticeViewRecordDao.insert(csSmNoticeViewRecord);
		return csSmNoticeDao.findById(id);
	}
}
